package com.cj.controller;

import com.cj.pojo.ArticleTrash;
import com.cj.service.ArticleTrashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@Controller
@RequestMapping("/articleTrash")
public class ArticleTrashController {

    @Autowired
    private ArticleTrashService articleTrashService;

    @GetMapping("/list")
    public String listTrash(Model model) {
        List<ArticleTrash> trashArticles = articleTrashService.listTrash();
        model.addAttribute("trashArticles", trashArticles);
        return "article_trash_list"; // 返回回收站列表页面
    }

    @PostMapping("/moveToTrash")
    public String moveToTrash(int id) {
        articleTrashService.moveToTrash(id);
        return "redirect:/articleTrash/list";
    }

    @PostMapping("/restore")
    public String restoreArticle(int trashId) {
        articleTrashService.restoreArticle(trashId);
        return "redirect:/articleTrash/list";
    }

    @PostMapping("/delete")
    public String deleteFromTrash(int trashId) {
        articleTrashService.deleteFromTrash(trashId);
        return "redirect:/articleTrash/list";
    }
}